﻿using BP.DA;
using BP.En;
using BP.Sys;
using BP.WF.Data;
using System;
using System.Data;

namespace BP.WF.DTS
{
    /// <summary>
    /// Method 的摘要说明
    /// </summary>
    public class AutoTask_DTS : Method
    {
        /// <summary>
        /// 不带有参数的方法
        /// </summary>
        public AutoTask_DTS()
        {
            this.Title = "自动任务Sys_AutoTask";
            this.Help = "自动任务Sys_AutoTask.";
            this.GroupName = "自定义自动任务";

        }
        /// <summary>
        /// 设置执行变量
        /// </summary>
        /// <returns></returns>
        public override void Init()
        {
        }
        /// <summary>
        /// 当前的操纵员是否可以执行这个方法
        /// </summary>
        public override bool IsCanDo
        {
            get
            {
                return true;
            }
        }
        /// <summary>
        /// 执行
        /// </summary>
        /// <returns>返回执行结果</returns>
        public override object Do()
        {
            //获得定时任务信息.
            AutoTasks tasks = new AutoTasks();
            tasks.RetrieveAllFromDBSource();

            int nowInt = int.Parse(DateTime.Now.ToString("HHmm"));
            //比如: 2009
            string strTimes = DateTime.Now.ToString("yyyy-MM-dd HH:MM");

            // "01 12:01,15 12:01"
            string msg = "";
            foreach (AutoTask rpt in tasks)
            {
                #region 判断是否达到执行的条件.
                string[] tims = rpt.Times.Split(',');
                bool isHave = false;
                foreach (string s in tims)
                {
                    if (strTimes.Contains(s) == false)
                        continue;

                    isHave = true;
                    break;
                }
                if (isHave == false)
                    continue;
                #endregion 判断是否达到执行的条件.

                msg += rpt.RunTask();
            }

            return "执行成功." + msg;

        }
    }
}
